'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Imports System.Collections.ObjectModel
Imports System.Linq

Public Class ContactsPageViewModel
    Inherits System.Windows.Threading.DispatcherObject

    Private _MasterGroup As GroupViewModel

    Public ReadOnly Property AvailableStatuses() As IEnumerable(Of IcqInterface.Interfaces.IStatusCode)
        Get
            Return ApplicationService.Current.Context.GetService(Of IStatusService).AvailableStatuses
        End Get
    End Property

    Public ReadOnly Property Contact() As IcqInterface.Interfaces.IContact
        Get
            Return ApplicationService.Current.Context.Identity
        End Get
    End Property

    Public ReadOnly Property Identity() As IdentityManager.IIdentity
        Get
            Return ApplicationService.Current.Identity
        End Get
    End Property

    Public ReadOnly Property MasterGroup() As GroupViewModel
        Get
            If _MasterGroup Is Nothing Then
                Dim svStorage = ApplicationService.Current.Context.GetService(Of IcqInterface.Interfaces.IStorageService)()

                _MasterGroup = GroupViewModelCache.GetViewModel(svStorage.MasterGroup)
            End If

            Return _MasterGroup
        End Get
    End Property

    Public Sub StartChatSessionWithContact(ByVal contact As ContactViewModel)
        Dim vm = ApplicationService.Current.Context.GetService(Of IContactWindowViewModelService).GetMessageWindowViewModel(contact)
        vm.Show()
    End Sub

    Public Sub CreateContextMenuForContact(ByVal menu As ContextMenu, ByVal contact As ContactViewModel)
        Dim sv As IContactContextMenuService

        sv = ApplicationService.Current.Context.GetService(Of IContactContextMenuService)()
        menu.Items.Clear()

        For Each x As MenuItem In sv.GetMenuItems(contact)
            menu.Items.Add(x)
        Next
    End Sub

    Public Sub ChangeStatus(ByVal status As IcqInterface.IcqStatusCode)
        Dim sv As IStatusService

        sv = ApplicationService.Current.Context.GetService(Of IStatusService)()

        sv.SetIdentityStatus(status)
    End Sub

    Public Sub SignOut()
        Dim svConnect As IcqInterface.Interfaces.IConnector

        svConnect = ApplicationService.Current.Context.GetService(Of IcqInterface.Interfaces.IConnector)()
        svConnect.SignOut()
    End Sub
End Class
